package iss.java;

import iss.java.list.MyList;
import iss.java.list.Node;

/**
 * Created by wenke on 2016/9/16.
 */
public class Main_B {
    public static final Object obj = new Object();

    public static void main(String[] args)throws InterruptedException {
        // TODO: Write a multithreaded testcase against requirement B.
        // NOTE: Testcase for requirement C is not required.

        MyList list = new MyList();

       for(int i = 0;i < 5; ++i){
           list.insert(list.getHead(),i+1);
       }

       Thread ta = new Thread(){
           @Override
           public void run(){
               synchronized (obj){
                   for(Node n = list.getHead().getNext(); n!=list.getTail(); n=n.getNext()){
                       System.out.printf("%d",n.getData());
                   }
                   System.out.println();
               }
           }
       };

       Thread tb = new Thread(){
           @Override
           public void run(){
               synchronized (obj){
                   list.remove(list.getHead().getNext().getNext());
                   for(Node n = list.getTail().getPrev(); n!=list.getHead(); n=n.getPrev()){
                       System.out.printf("%d", n.getData());
                   }
                   System.out.println();
               }
           }
       };

        ta.start();
        tb.start();
        Thread.sleep(100);
    }


}
